package com.eeb.dropwizardmongo.example.api;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotBlank;
import org.mongojack.MongoCollection;
import org.mongojack.ObjectId;

import java.util.ArrayList;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
@MongoCollection(name = "users")
public class User {

    @JsonProperty("_id")
    private String _id;

    @NotBlank
    @JsonProperty("firstName")
    private String firstName;

    @NotBlank
    @JsonProperty("lastName")
    private String lastName;

    @NotBlank
    @JsonProperty("userName")
    private String userName;

    @NotBlank
    @JsonProperty("password")
    private String password;
    
    @NotBlank
    @JsonProperty("email")
    private String email;

    @JsonProperty("siteAdmin")
    private boolean siteAdmin = false;

    @JsonProperty("reputation")
    private int reputation = 0;

    @JsonProperty("badges")
    private List<String> badges = new ArrayList<>();

    @JsonProperty("organizations")
    private List<String> organizations = new ArrayList<>();
    
    @JsonProperty("assignments")
    private List<String> assignments = new ArrayList<>();

    @JsonProperty("assignedOrgs")
    private List<String> assignedOrgs = new ArrayList<>();

    public User() {
    }

    public User(@ObjectId String _id, String firstName, String lastName, String userName, String password, String email, Boolean siteAdmin) {
        this._id = _id;
        this.firstName = firstName;
        this.lastName = lastName;
        this.userName = userName;
        this.password = password;
        this.email = email;
        this.siteAdmin = siteAdmin;
    }

    @ObjectId
    public String get_id() {
        return _id;
    }

    public void set_id(String _id) {
        this._id = _id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public boolean isSiteAdmin() {
        return siteAdmin;
    }

    public void setSiteAdmin(boolean siteAdmin) {
        this.siteAdmin = siteAdmin;
    }

    public int getReputation() {
        return reputation;
    }

    public void setReputation(int reputation) {
        this.reputation = reputation;
    }

    public List<String> getBadges() {
        return badges;
    }

    public void setBadges(List<String> badges) {
        this.badges = badges;
    }

    public void addBadge(String badge) {
        badges.add(badge);
    }

    public boolean removeBadge(String badge) {
        return badges.remove(badge);
    }

    public boolean hasBadge(String badge) {
        return badges.contains(badge);
    }

    public List<String> getOrganizations() {
        return organizations;
    }

    public void setOrganizations(List<String> organizations) {
        this.organizations = organizations;
    }

    public void addOrg(String org) {
        if (!organizations.contains(org)) organizations.add(org);
    }
    
    public boolean removeOrg(String org) {
        return badges.remove(org);
    }

    public boolean hasOrg(String org) {
        return organizations.contains(org);
    }

    public List<String> getAssignments() {
        return assignments;
    }

    public void setAssignments(List<String> assignments) {
        this.assignments = assignments;
    }

    public void addAssignment(String user) {
        if (!assignments.contains(user)) assignments.add(user);
    }

    public boolean removeAssignment(String user) {
        return assignments.remove(user);
    }

    public boolean hasAssignment(String user) {
        return assignments.contains(user);
    }

    public List<String> getAssignedOrgs() {
        return assignedOrgs;
    }

    public void setAssignedOrgs(List<String> assignedOrgs) {
        this.assignedOrgs = assignedOrgs;
    }

    public void addAssignedOrg(String assignedOrg) {
        if (!assignedOrgs.contains(assignedOrg)) assignedOrgs.add(assignedOrg);
    }

    public boolean removeAssignedOrg(String assignedOrg) {
        return assignedOrgs.remove(assignedOrg);
    }

    public boolean hasAssignedOrg(String assignedOrg) {
        return assignedOrgs.contains(assignedOrg);
    }

}
